<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div class="path-mappings__header">
  <h2>Path Mappings</h2>
  <div>
    <ng-container *ngIf="!isReadOnly">
      <button *gioPermission="{ anyOf: ['api-definition-u'] }" mat-raised-button type="button" color="primary" (click)="addPathMapping()">
        <mat-icon svgIcon="gio:plus"></mat-icon>
        Add New Path Mapping
      </button>
    </ng-container>
  </div>
</div>

<div class="path-mappings">
  <table mat-table id="pathMappingsTable" aria-label="Path mappings table" class="path-mappings__table" [dataSource]="pathMappingsDS">
    <!-- Path Column -->
    <ng-container matColumnDef="path">
      <th mat-header-cell *matHeaderCellDef id="path">Path</th>
      <td mat-cell *matCellDef="let element">
        {{ element.path }}
      </td>
    </ng-container>

    <!-- Actions Column -->
    <ng-container matColumnDef="actions">
      <th mat-header-cell *matHeaderCellDef id="actions"></th>
      <td mat-cell *matCellDef="let element">
        <div class="path-mappings__table__actions" *ngIf="!isReadOnly">
          <button
            mat-icon-button
            aria-label="Button to edit a path mapping"
            matTooltip="Edit path mapping"
            *gioPermission="{ anyOf: ['api-definition-u'] }"
            (click)="editPathMapping(element.path)"
          >
            <mat-icon svgIcon="gio:edit-pencil"></mat-icon>
          </button>
          <button
            *gioPermission="{ anyOf: ['api-definition-u'] }"
            mat-icon-button
            aria-label="Button to delete a path mapping"
            matTooltip="Delete path mapping"
            (click)="deletePathMapping(element.path)"
          >
            <mat-icon svgIcon="gio:trash"></mat-icon>
          </button>
        </div>
      </td>
    </ng-container>

    <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
    <tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>

    <!-- Row shown when there is no data -->
    <tr class="mat-mdc-row mdc-data-table__row" *matNoDataRow>
      <td
        *ngIf="!isLoadingData && pathMappingsDS.length === 0"
        class="mat-mdc-cell mdc-data-table__cell"
        [attr.colspan]="displayedColumns.length"
      >
        No Path Mappings
      </td>
      <td *ngIf="isLoadingData" class="mat-mdc-cell mdc-data-table__cell" [attr.colspan]="displayedColumns.length">
        {{ 'Loading...' }}
      </td>
    </tr>
  </table>
</div>
